﻿using Microsoft.AspNetCore.Mvc;
using WorldmeServer.DTO.用户相关;
using WorldmeServer.Services.Business.用户相关;

namespace WorldmeServer.Controllers.用户相关
{
    [ApiController]
    [Route("api/auth")]
    
    public class AuthController : ControllerBase
    {
        private readonly AuthService authService;

        public AuthController(AuthService authService)
        {
            this.authService = authService;
        }

        [HttpPost]
        [Route("register")]
        [JwtNoAuthorize]
        public async Task<IActionResult> Register([FromBody] RegisterUserDTO dto)
        {
            var result = await authService.Register(dto);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }

        [HttpPost]
        [Route("login")]
        [JwtNoAuthorize]
        public async Task<IActionResult> Login([FromBody] LoginUserDto dto)
        {
            var result = await authService.Login(dto);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }

        [HttpPost]
        [Route("send")]
        [JwtNoAuthorize]
        public async Task<IActionResult> Send(SendEmailDto dto)
        {
            var result = await authService.SendVerificationEmail(dto);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }
    }
}
